<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>数据分析</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- css -->
<link href="../static/css/bootstrap-responsive.css" rel="stylesheet">
<link href="../static/css/style.css" rel="stylesheet">
<!-- skin color -->
<link href="../static/color/default.css" rel="stylesheet">
<!--[if lt IE 7]>
	<link href="css/font-awesome-ie7.css" type="text/css" rel="stylesheet">  
<![endif]-->
<link rel="shortcut icon" href="../static/img/favicon.ico">
<style type="text/css">
	.content{
		margin-left:4%;
        margin-right:4%;
	}
</style>
</head>
<body>
<!-- navbar -->
<div class="navbar-wrapper">
	<div class="navbar navbar-inverse navbar-fixed-top">
		<div class="navbar-inner">
			<div class="container">
				<!-- Responsive navbar -->
				<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
				</a>
				<h1 class="brand"><a href="index.html" tppabs="#">DataAnalysis</a></h1>
				<!-- navigation -->
				<nav class="pull-right nav-collapse collapse">
				<ul id="menu-main" class="nav">
                    <li><a title="team" href="/index.html">主页</a></li>
                    <li><a title="services" href="/analysis.html">数据分析</a></li>
                    <li><a title="works" href="/blog/category/应用案例">案例系统</a></li>
                    <li><a title="blog" href="/blog/category/代码开源">开源论坛</a></li>
                    <li><a title="contact" href="/help.html">帮助中心</a></li>
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="#"><span class="glyphicon glyphicon-user"></span>{{ user }}</label></a></li>
                    </ul>
                </ul>
				</nav>
			</div>
		</div>
	</div>
</div>

<!-- section: team -->
<section id="about" class="section">
<div class="container" >


    <h4>{% block title %}关于KNN{% endblock %}</h4>
    <hr>
    <div class="row">
        <div class="span12 content">
        {% block description %}
            <p><b>KNN</b>，亦称K-近邻，此算法采用测量不同特征值之间的距离方法进行分类。</p>
            <p><b>工作原理：</b>存在一个样本数据集合，也称作训练样本集，并且样本集中每个数据都存在标签，即我们知道样本集中每一数据与所属分类的对应关系。输入没有标签的新数据后，将新数据的每个特征与样本集中数据对应的特征进行比较，然后算法提取出样本集中特征最相似（最近邻）的分类标签。</p>
            <p><b>K值含义：</b>一般来说，我们只选择样本数据集中前K个最相似的数据，这就是K-近邻算法中K的出处。即K的值为一个大于0的整数。</p>
            <p><b>待测数据：</b>输入一组类别未知的样本的数据，各个数据之间用英文逗号分隔。系统会给出待测对象的分类。</p>
            <p><b>算法优点：</b>精度高、对异常值不敏感、无数据输入假定。</p>
            <p><b>算法缺点：</b>计算复杂度高、空间复杂度高。</p>
            <p><b>适用数据范围：</b>数值型、标称型。</p>
        {% endblock %}
            <hr><br>


                <h4>数据输入处</h4>

                {% block input %}

                <div class="span9">
                <form class="bs-example bs-example-form " method="post" name="knn" role="form" action="" enctype="multipart/form-data">
                {% csrf_token %}
                <!--格式-->
                  
                    <label>k值:</label>
                    <input type="text" class="form-control" placeholder="请输入合适的k值" name="value_k" value="{{ k }}" required="required">
                    <label>测试数据:</label>
                    <input type="text" class="form-control" placeholder="数字间用英文逗号分隔" name="testset_input" value="{{ test_set }}" required="required">
                    <input type="file" name="csv" required="required" > 
                    <p class="form-btn">
                        <button type="submit" class="btn btn-primary btn-lg " name="ok" onclick=draw()>上传文件</button>
                    </p>
                </form>
                </div>

                {% endblock %}
        </div>        
    </div>

<!-- /.container -->

{% block resu %}  

{% if label %}
<hr>
<p><h4>分析结果 </h4></p>
<br>


    {% ifequal length 2 %}
    
    <!-- 为ECharts准备一个具备大小（宽高）的Dom(训练集属性值=2时) -->
    <div id="knn_2" style="height:400px;margin-left:2%;margin-right:2%;"></div>
    <!-- ECharts单文件引入 -->
    <script src="http://echarts.baidu.com/build/dist/echarts-all.js"></script>
    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts图表
var myChart = echarts.init(document.getElementById('knn_2')); 
myChart.showLoading({text: "图表数据正在努力加载..."});

var option = {
    title : {
        text: '类别散点图',
        subtext: '结果仅供参考'
    },
    tooltip : {
        trigger: 'axis',
        showDelay : 0,
        axisPointer:{
            show: true,
            type : 'cross',
            lineStyle: {
                type : 'dashed',
                width : 1
            }
        }
    },
    legend: {
        data: {{ all_labels|safe }}   // 类别
    },
    toolbox: {
        show : true,
        feature : {
            mark : {show: true},
            dataZoom : {show: true},
            dataView : {show: true, readOnly: false},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    xAxis : [
        {
            name :{{ shuxing0|safe }},
            type : 'value',
            scale:true,
            axisLabel : {
                formatter: '{value}'
            }
        }
    ],
    yAxis : [
        {
            name :{{ shuxing1|safe }},
            type : 'value',
            scale:true,
            axisLabel : {
                formatter: '{value}'
            }
        }
    ],
    series : {{ data|safe }}
};
        // 为echarts对象加载数据 
        myChart.hideLoading(); 
        myChart.setOption(option);
        
    </script>


    {% else %} 

<!-- 为ECharts准备一个具备大小（宽高）的Dom(训练集属性值>2时) -->
    <div id="knn" style="height:500px;margin-left:2%;margin-right:2%;"></div>   
    <!-- ECharts单文件引入 -->
    <script src="http://echarts.baidu.com/build/dist/echarts-all.js"></script>
    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts图表
        var myChart = echarts.init(document.getElementById('knn')); 
        
        var option = {
    title : {
        text: '类别雷达图',
        subtext: '结果仅供参考'
    },
    tooltip : {
        trigger: 'axis'
    },
    legend: {
        orient : 'vertical',
        x : 'right',
        y : 'bottom',
        data:{{ all_labels|safe}}
    },
    toolbox: {
        show : true,
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: false},
            restore : {show: true},
            saveAsImage : {show: true}
        }
    },
    polar : [
       {
           indicator : {{ indicator|safe }}
        }
    ],
    calculable : true,
    series : [
        {
            name: '类别雷达图',
            type: 'radar',
            data : {{ data|safe }}
        }
    ]
};
        // 为echarts对象加载数据 
        myChart.setOption(option); 
    </script>
    {% endifequal %}

<hr>
<div class="content">

<p>该样本中共有 <b>{{ len_labels }}</b> 种不同类别</p>
<p>您输入的待分类对象数据为：<b>{{ test_set }}</b>。</p>
<p>由样本分析得，该对象属于"<b>{{ label }}</b>"类。 </p>
<br><br>

</div>
</div>

{% else %}
<p>&nbsp;</p>


{% endif %}
{% endblock %}


</div>
</div>
</div>

</div>
</section>

<footer>
<div class="container">
    <div class="row">
        <div class="span6 offset3">
            <ul class="social-networks">
                <li><a href="#"><i class="icon-circled icon-bgdark icon-instagram icon-2x"></i></a></li>
                <li><a href="#"><i class="icon-circled icon-bgdark icon-twitter icon-2x"></i></a></li>
                <li><a href="#"><i class="icon-circled icon-bgdark icon-dribbble icon-2x"></i></a></li>
                <li><a href="#"><i class="icon-circled icon-bgdark icon-pinterest icon-2x"></i></a></li>
            </ul>
            <p class="copyright">Copyright &copy;  <a href="http://sjfx.piclass.cn" target="_blank" title="数据分析">sjfx.piclass.cn</a> 
</p>
        </div>
    </div>
</div>
<!-- ./container -->
</footer>
<a href="#" class="scrollup"><i class="icon-angle-up icon-square icon-bgdark icon-2x"></i></a>
<!-- jQuery -->
<script src="../static/js/jquery.js"></script>
<!-- nav -->
<script src="../static/js/jquery.scrollTo.js"></script>
<script src="../static/js/jquery.nav.js"></script>
<!-- localScroll -->
<script src="../static/js/jquery.localscroll-1.2.7-min.js"></script>
<!-- bootstrap -->
<script src="../static/js/bootstrap.js"></script>
<!-- prettyPhoto -->
<script src="../static/js/jquery.prettyPhoto.js"></script>
<!-- Works scripts -->
<script src="../static/js/isotope.js"></script>
<!-- flexslider -->
<script src="../static/js/jquery.flexslider.js"></script>
<!-- inview -->
<script src="../static/js/inview.js"></script>
<!-- animation -->
<script src="../static/js/animate.js"></script>
<!-- twitter -->
<script src="../static/js/jquery.tweet.js"></script>
<!-- contact form -->
<script src="../static/js/validate.js"></script>
<!-- custom functions -->
<script src="../static/js/custom.js"></script>
</body>
</html>